public class test {
    Deque<Integer> deque1;
    Deque<Integer> deque2;
    public MyStack() {
        deque1 = new LinkedList<>();
        deque2 = new LinkedList<>();
    }

    public void push(int x) {
        deque2.offer(x);
        while(!deque1.isEmpty()){
            deque2.offer(deque1.poll());
        }
        Deque tmp = deque1;
        deque1 = deque2;
        deque2 = tmp;
    }

    public int pop() {
        return deque1.pop();
    }

    public int top() {
        return deque1.peek();
    }

    public boolean empty() {
        return deque1.isEmpty();
    }
}
